﻿using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace demo
{


    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
    [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
    public class Synthesis : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Autodesk.Revit.DB.Document document = commandData.Application.ActiveUIDocument.Document;
            Transaction tran = new Transaction(document, "合成1");
            tran.Start();
            DirectShape ds = DirectShape.CreateElement(document, new ElementId(BuiltInCategory.OST_GenericModel));

           // BooleanOperation.BooleanOperation_Intersect


            var entity = new EntityInfo();
            //var solid1 = entity.CreateBox(XYZ.Zero, 25);
            //var solid2 = entity.CreateSphere(XYZ.Zero, 15);
            //var solid= entity.Difference(solid1,solid2);


            var solid1 = entity.CreateCylinder(XYZ.Zero, 25, 10, GeometryCreation.CylinderDirection.BasisX);
            var solid2 = entity.CreateCylinder(XYZ.Zero, 24, 10, GeometryCreation.CylinderDirection.BasisX);
            var solid = entity.Difference(solid1, solid2);

            //var solid1 = entity.CreateBox(XYZ.Zero, 20);
            //var solid2 = entity.CreateSphere(new XYZ(0,0,10),5);
            //var solid = entity.Difference(solid1, solid2);


            ds.SetShape(new List<GeometryObject>() { solid});
            tran.Commit();
            return Result.Succeeded;
        }
    }

}
